﻿using System.Linq;
using KTOP.Core.Netlists;

namespace KTOP.Core.Domain.Matrix
{
    public class RMatrix : MatrixWithSumms
    {
        public RMatrix(int[][] matrix)
            : base(matrix)
        {
        }

        public static RMatrix CreateFromNetlist(Netlist netlist)
        {
            var rMatrix = CreateEmptyMatrix(netlist.ModuleCount);

            foreach (var net in netlist.Nets)
                foreach (var cPin in net.Pins)
                {
                    var pin1 = cPin;
                    foreach (var pin2 in net.Pins.Where(p => p.Module.Id!=pin1.Module.Id))
                        rMatrix[pin1.Module.Id][pin2.Module.Id]++;
                }


            return new RMatrix(rMatrix);
        }
    }
}
